<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>父访问子2-ref</title>
    <script src="../lib/vue_v2.6.14.js"></script>
  </head>
  <body>
    <div id="app">
      <cpn-son ref="sonRef"></cpn-son>
      <button @click="btnClick">按钮</button>
    </div>

    <template id="cpn">
      <div></div>
    </template>
    <script>
      // 子组件
      Vue.component('cpn-son', {
        template: '#cpn',
        data() {
          return {
            message: '我要下班了'
          }
        }
      })

      // 父组件
      const vm = new Vue({
        el: '#app',
        data: {},
        methods: {
          btnClick() {
            console.log('ref--', this.$refs.sonRef.message)
          }
        }
      })
    </script>
  </body>
</html>
